<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="net.netca.gdltax.bpms.webservice.*"%>
<%@page import="net.netca.gdltax.bpms.businessmanage.bo.*"%>
<%@page import="java.util.*"%>
<%@page import="net.netca.testwebservice.bo.XMLConfig"%>

<%
	//CertServiceClient client = new CertServiceClient(
	//		"http://192.168.0.37:8082/businessmanage/services/CertService");
			
	//System.out.println(XMLConfig.getInstance().getUrl());
	CertServiceClient client = new CertServiceClient(
			XMLConfig.getInstance().getUrl());
	CertServicePortType service = client.getCertServiceHttpPort();
	List<CA> cas = service.getAllCA().getCA();
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>

		<script type="text/javascript">
		﻿function getp10(caname,p10name,keytypename,keysnname,dn)
		{	
			var p10Value = document.getElementById('p10').value;
			if(p10Value==null || p10Value=="")
			{
				var obj;
				try
				{
					obj = new ActiveXObject("NetcaBpmsClientCom.PKI");
					
					if(obj.IsInstalled(caname))
					{
						obj.SetCA(caname);
						if(obj.KeyCount>1)
						{
							alert("最多只能插入1个key");
							return;
						}
						
						obj.Connect();
						
						if(keytypename!="")
						{
							document.getElementById(keytypename).value=obj.Type;
						}
						if(keysnname!="")
						{
							document.getElementById(keysnname).value=obj.SerialNumber;
						}
						
						document.getElementById(p10name).value=obj.GenerateP10(dn);
						
						//alert("生成证书密钥对成功");
					}
					else
					{
						alert("没有安装该CA的支持的DLL");
					}
				}
				catch (e)
				{
					alert(e.message);
				}
			}
		}
		
		function getdn(E,CN,OU,O,L,S,C)
		{
		//E-CN-OU-O-L-S-C
		//email-??????-????-??λ-????-?-???
			var dn="";
			var count=0;
			if(E!="")
			{
				if(count>0)
					dn+=",";
				dn+="E="+E;
				count++;
			}
			if(CN!="")
			{
				if(count>0)
					dn+=",";
				dn+="CN="+CN;
				count++;
			}
			if(OU!="")
			{
				if(count>0)
					dn+=",";
				dn+="OU="+OU;
				count++;
			}
			if(O!="")
			{
				if(count>0)
					dn+=",";
				dn+="O="+O;
				count++;
			}
			if(L!="")
			{
				if(count>0)
					dn+=",";
				dn+="L="+L;
				count++;
			}
			if(S!="")
			{
				if(count>0)
					dn+=",";
				dn+="S="+S;
				count++;
			}
			if(C!="")
			{
				if(count>0)
					dn+=",";
				dn+="C="+C;
				count++;
			}
			
			return dn;
		}
		</script>
	</head>
	<body>
		<form action="servlet/requestcert" method="post">
			<br>
			<br>
			CA名称：
			<input name="caname" id="caname" value="广东省电子商务认证中心">
			<br>
			纳税人名称：
			<input name="name" id="name">
			<br>
			纳税人编号：
			<input name="taxpayerid" id="taxpayerid">
			<br>
			子用户编号：
			<input name="subuserid" id="subuserid">
			<br>
			有&nbsp效&nbsp期：
			<input name="validity" id="validity">
			<br>
			是否网报用户：是
			<input type="radio" name="iswebuser" id="iswebuser" value="1">
			否
			<input type="radio" name="iswebuser" id="iswebuser" value="0"
				checked="true">
			<br>
			ca编号：
			<br>
			<%
				for (int i = 0; i < cas.size(); i++) {
			%>
			<input type="radio" name="caid" id="caid"
				value="<%=cas.get(i).getId()%>" <%=i == 0 ? "checked" : ""%>><%=cas.get(i).getName().getValue()%>
			<br>
			<%
				}
			%>

			<input type="button" id="genp10"
				onclick="getp10(document.getElementById('caname').value,'p10','keytype','keysn',getdn('',document.getElementById('name').value,'',document.getElementById('name').value,'','Guangdong','CN'))"
				value="生成证书密钥对" class="colorCCC2" style="width: 100px">
			<br>
			
			<input id="p10" name="p10" type="text" readonly
				style="width: 0px; border: 0px" value="">

			证书类型：
			<input name="keytype" id="keytype" readonly>
			<br>
			证书介质编号：
			<input name="keysn" id="keysn" readonly>
			<br>

			<input type="submit" value="提交">
		</form>
	</body>
</html>